Skip to content

Patch vendored wombat.js to convert POST to GET in fetch() - #379

Merged
benoit74 merged 1 commit into
mainfrom
fix-wombat-fetch-post-to-get
Nov 5, 2026
Merged

benoit74 merged 1 commit into
mainfrom
fix-wombat-fetch-post-to-get

Conversation

@benoit74

@benoit74 benoit74 commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • wombat.js's fetch() override only rewrites the request URL; it does not convert a POST (or other non-GET) request to GET the way its XMLHttpRequest override already does. Anything fetched via a POST fetch() call (e.g. YouTube's embedded player fetching its InnerTube player-config) is therefore sent as a literal POST to kiwix-serve, which only serves the GET-converted content baked into the ZIM at scrape time, and 404s. The player's JSON.parse() of the 404 HTML page then throws, breaking video playback right after the user clicks Play.
  • A fix has been proposed upstream (fetch(): convert POST (and other non-GET) requests to GET webrecorder/wombat#242), using wombat's own postToGetUrl(), which flattens the POST body into the query string. That does not match how warc2zim currently names a POST-converted ZIM entry (just <original-url>&__wb_method=<METHOD>, with the body dropped — verifiable directly on a built ZIM for the youtubei/v1/player, youtubei/v1/next and WAA GenerateIT entries), so rules/patch_wombat.py intentionally uses that simpler, body-dropping convention instead, to stay consistent with how ZIMs are actually built today.
  • Wired in via a new execute_after hook on the wombat.js download action in openzim.toml, so every build patches the freshly downloaded wombat.js. The script is idempotent (a no-op if wombat.js is already patched) and fails loudly if the vendored wombat.js no longer matches the expected code, so a future version bump can't silently skip the fix.

Reproduced and validated against the real website.test.openzim.org YouTube test ZIM: rebuilt it with the patched wombat.js and confirmed via a headless browser that the previously-404ing youtubei/v1/player request now returns 200 and the video actually plays (readyState: 4, paused: false, currentTime advancing), versus stuck at readyState: 0 / paused: true before the patch.

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4cbfe83) to head (2d0451e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #379   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           42        42           
  Lines         2867      2867           
  Branches       432       432           
=========================================
  Hits          2867      2867           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

wombat.js's fetch() override only rewrites the request URL: it does not
convert a POST (or other non-GET) request to GET the way its
XMLHttpRequest override already does, so anything fetched via a POST
fetch() call (e.g. YouTube's embedded player fetching its InnerTube
player-config) is sent as a literal POST to kiwix-serve, which only
serves the GET-converted content baked into the ZIM, and 404s.

A fix has been proposed upstream (webrecorder/wombat#242), using wombat's
own postToGetUrl(), which flattens the POST body into the query string.
That does not match how warc2zim currently names a POST-converted ZIM
entry (just `<original-url>&__wb_method=<METHOD>`, body dropped), so
this patch intentionally uses that simpler convention instead, to stay
consistent with how ZIMs are actually built today.

Applied via a new execute_after hook on the wombat.js download in
openzim.toml, so every build patches the freshly downloaded wombat.js.
@benoit74
benoit74 force-pushed the fix-wombat-fetch-post-to-get branch from 7541511 to 2d0451e Compare November 5, 2026 09:23
@benoit74 benoit74 self-assigned this Nov 5, 2026
@benoit74
benoit74 merged commit 5f93f6b into main Nov 5, 2026
10 checks passed
@benoit74
benoit74 deleted the fix-wombat-fetch-post-to-get branch November 5, 2026 10:15
@benoit74 benoit74 added this to the 5.5.2 milestone Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant